
<template>
  <el-dialog
    title="重命名"
    :visible.sync="isShow"
    width="400px"
    @close="handleClose"
  >
    <el-form ref="form" :model="form" label-width="80px" :rules="rules" @submit.native.prevent>
      <el-form-item label="专栏名称" prop="columnName">
        <el-input v-model="form.columnName" @keydown.enter.native="submitForm" ></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
    <el-button @click="handleClose">取 消</el-button>
    <el-button type="primary" @click="submitForm">确 定</el-button>
  </span>
  </el-dialog>
</template>
<script >
import { saveColumnInfo } from '@/api/showColumn'

export  default {
  name: 'RenameDialog',
  data(){
    return{
      isShow:false,
      form:{
        columnName:''
      },
      rules: {
        columnName: [
          { required: true, message: '请输入专栏名称', trigger: 'blur' },
          { max: 10, message: '最多不能超过10个字符，请重新输入', trigger: 'blur' }
        ]
      },
    }
  },
  methods:{
    show(item){
      this.form=JSON.parse(JSON.stringify(item));
      this.isShow = true;
    },
    handleClose(){
      this.$refs['form'].resetFields();
      this.isShow = false;
      // this.$message.info('已取消')
    },
    submitForm(){
      this.$refs['form'].validate(async(valid) => {
        if (valid) {
          try{
            let res=await saveColumnInfo(this.form);
            if(res.code==200){
              this.handleClose();
              this.$message.success('修改成功');
              this.$emit('refresh');
            }
          }catch (err){
            console.log(err)
          }
        } else {
          return false;
        }
      });
    }
  }
}

</script>
<style scoped lang="scss">

</style>
